﻿using System.Web.Mvc;
using Jw.Models;
using System.Web.Http;
using Jw.Core;
using Jw.Web.App_Start;

namespace Jw.Web.Areas.Dev.Controllers
{
    /// <summary>
    /// 统计查询报表 
    /// </summary>
    public class ReportController : BaseController
    {
        //设备台账（统计 )
        // GET: /Dev/Report/

        public ActionResult SbtzAccount()
        {
            var codeService = new sys_codeService();
            var model = new
            {
                idField = "Sbda_Sbbm", //主键
                urls = new
                {
                    query = "/api/Dev/Report/GetSbtzAccount/"
                },
                dataSource = new
                {
                    sbztItems = codeService.GetTextListByType("Sbzt"),//设备状态
                    yearItems = codeService.GetYearItems(),
                    monthItems = codeService.GetMonthItems()
                },
                form = new
                {
                    Sbda_lbbh = "", //类别
                    Sbda_Sbzt = "",  //状态
                    Sbda_Sbmc = "", //名称
                    CreateDate =""
                }
            };
            return View(model);
        }

    }


    public class ReportApiController : ApiController
    {
        //"/api/dev/Report/GetSbtzAccount/"
        public dynamic GetSbtzAccount(RequestWrapper query)
        {
            query.LoadSettingXmlString(@"
            <settings defaultOrderBy='a.Sbda_Sbbm DESC'>
            <select>a.*,b.Sblbzd_Lbbh,b.Sblbzd_Lbmc </select>
                <from>b_Sbda a  
                      left outer join dbo.b_Sblbzd b on b.Sblbzd_Lbbh = a.Sbda_lbbh
                </from>
                <where defaultForAll='true' defaultCp='equal' defaultIgnoreEmpty='true' >
                    <field name='a.Sbda_Sbbm'     cp='like'></field>
                    <field name='a.CreateDate'    cp='daterange'></field>
                </where>
            </settings>");
            var service = new b_SbdaService();
            var pQuery = query.ToParamQuery();
            var result = service.GetDynamicListWithPaging(pQuery);

            return result;
        }

    }
}
